package me.minecraft.plugin.pokemondenyconvert.config;

import com.cobblemon.mod.common.pokemon.Pokemon;
import lombok.Getter;
import me.minecraft.plugin.pokemondenyconvert.util.PokemonList;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.List;

/**
 * @author langle__
 * @version 1.0
 */
public class MainConfig {

    private final JavaPlugin plugin;
    private final File file;

    @Getter private String reloadMessage;
    @Getter private String message;
    @Getter private boolean pokemonToItem;
    @Getter private boolean itemToPokemon;
    @Getter private PokemonList pokemonList;

    public MainConfig(JavaPlugin plugin) {
        this.plugin = plugin;
        this.file = new File(plugin.getDataFolder(), "config.yml");
        this.loadConfig();
    }

    public void loadConfig() {
        if (!file.exists()) plugin.saveResource("config.yml", false);

        FileConfiguration config = YamlConfiguration.loadConfiguration(file);

        this.reloadMessage = config.getString("reloadMessage", "[§6宝可梦禁止转换§f] 配置重新加载");
        this.message = config.getString("message", "[§6宝可梦禁止转换§f] 该宝可梦禁止转换");

        this.pokemonToItem = config.getBoolean("pokemonToItem");
        this.itemToPokemon = config.getBoolean("itemToPokemon");

        List<String> whiteList = config.getStringList("whiteList");
        List<String> blackList = config.getStringList("blackList");
        this.pokemonList = new PokemonList(whiteList, blackList);
    }

    public boolean matches(Pokemon pokemon) {
        return pokemonList.matches(pokemon);
    }

}
